package com.example.meituan.activity.man;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.SearchView;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.example.meituan.R;
import com.example.meituan.activity.man.adapter.OrderListAdapter;
import com.example.meituan.activity.bean.AdminBean;
import com.example.meituan.activity.bean.OrderBean;
import com.example.meituan.dao.AdminDao;
import com.example.meituan.dao.OrderDao;

import java.util.List;

public class ManageOrderActivity extends AppCompatActivity {
    private AdminBean currentUser;
    private AdminDao adminDao;
    private OrderDao orderDao;
    private OrderListAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_manage_order); // 设置内容视图必须放在最前面

        EdgeToEdge.enable(this);

        adminDao = new AdminDao();
        orderDao = new OrderDao();

        currentUser = adminDao.getUserInfo(this);

        // 查找 ListView 并设置适配器
        ListView listView = findViewById(R.id.man_order_listView);
        List<OrderBean> list = orderDao.getAllOrdersByBusinessId(currentUser.getUserId());

        if (list == null || list.isEmpty()) {
            Toast.makeText(this, "没有数据显示", Toast.LENGTH_SHORT).show();
            listView.setAdapter(null);
        } else {
            adapter = new OrderListAdapter(this, list);
            listView.setAdapter(adapter);
        }
        ImageView img=findViewById(R.id.order_back);
        img.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();//返回功能
                //finish();
            }
        });
//        androidx.appcompat.widget.SearchView searchView=findViewById(R.id.order_home_shop_listView_search);
//        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
//            @Override
//            public boolean onQueryTextSubmit(String query) {
//                OrderDao.
//                return false;
//            }
//
//            @Override
//            public boolean onQueryTextChange(String newText) {
//                return false;
//            }
//        });
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });
    }
}